import { Todo } from './models/todo';
import { Action } from '@ngrx/store';
const ui = {
  START_EDITING: 'UI_START_EDITING',
  UPDATE_EDITING: 'UPDATE_EDITING',
  CANCEL_EDITING: 'UI_CANCEL_EDITING',
  STOP_EDITING: 'UI_STOP_EDITING',
  TOGGLE_COMPLETION: 'UI_TOGGLE_COMPLETION',

  ADD_TODO: 'UI_ADD_TODO'
}

export const actions = {
  ui
}

export function addTodo(title): Action {
  return { type: actions.ui.ADD_TODO, payload: title }
}

export function startEditing(todo: Todo): Action {
  return { type: actions.ui.START_EDITING, payload: todo }
}

export function updateEditing(todo: Todo, value): Action {
  return { type: actions.ui.UPDATE_EDITING, payload: { todo, value } }
}

export function stopEditing(todo: Todo, value): Action {
  return { type: actions.ui.STOP_EDITING, payload: { todo, value } }
}

export function cancelEditing(todo: Todo): Action {
  return { type: actions.ui.CANCEL_EDITING, payload: todo }
}

export function toggleCompletion(todo: Todo): Action {
  return { type: actions.ui.TOGGLE_COMPLETION, payload: todo }
}
